package com.ibk.system;

import java.util.HashMap;
import java.util.Map;

import com.ibk.system.media.VodPlayerViewActivity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class MenuViewActivity extends Activity implements OnClickListener {
	public Button[] buttons;
	public Map<Integer, Integer> btToId;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.menu);
		int nButtonSize = getResources().getStringArray(R.array.url_array).length;
		if (buttons == null) {
			buttons = new Button[nButtonSize];
			btToId = new HashMap<Integer, Integer>();
			// "리소스명", "타입", "패키지명"
			for (int i = 0; i < nButtonSize; i++) {
				int id = getResources().getIdentifier("bt" + (i + 1), "id",
						getPackageName());
				buttons[i] = (Button) findViewById(id);
				buttons[i].setOnClickListener(this);
				btToId.put(buttons[i].getId(), i);
			}
		}
	}

	@Override
	public void onClick(View v) {
		int index = btToId.get(v.getId());
		String url;
		Intent it;
		if (buttons[4].getId() == v.getId()) {
			url = "http://ms.ibk.co.kr:7170/mov/oneclick0301a.mp4";
			it = new Intent(getApplicationContext(), VodPlayerViewActivity.class);
			it.putExtra("url", url);
		} else {
			url = getResources().getStringArray(R.array.url_array)[index];
			it = new Intent(getApplicationContext(), WebViewActivity.class);
			it.putExtra("url", url);
		}
		startActivity(it);
	}
}
